var fanhui = document.querySelector('header>a')
fanhui.onclick = function () {
    location.href = "../index.html"
}
//点击获取手机验证码的事件
var b = document.querySelector('form>b')
console.log(b)
b.onclick = function () {
    var x = 60
    b.innerText = x + '秒'
    var time1 = setInterval(() => {
        x--
        b.innerText = x + '秒'
        if (x === 1) {
            clearInterval(time1)
            b.innerText = '获取验证码'
        }
    }, 1000);

}
var h6=document.querySelector('h6')
//给手机号书写正则检测事件 /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/
// var regs=/^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/
var regs = /^[1]\d{10}$/
//获取输入的手机号的值
var shouji = document.querySelector('form>input:nth-of-type(1)')
console.log(shouji)
//获取提示信息框p
var p = $('form>p')
shouji.oninput = function () {
    h6.style.opacity=
    console.log(shouji.value)
    if (!regs.test(shouji.value)) {
        p.css({ display: 'block' })
        p.text('手机号不正确')
        if (shouji.value === "") {
            p.css({ display: 'none' })
        }
    }
    else if (regs.test(shouji.value)) {
        // p.css({display:'block'})
        p.text('手机号码正确')
    }
}
//一打开页面或者刷新页面需要得到新的 验证码
var i = document.querySelector('form>i')
console.log(i)
var A = parseInt(Math.random() * 10)
var B = parseInt(Math.random() * 10)
var C = parseInt(Math.random() * 10)
var D = parseInt(Math.random() * 10)
i.innerText = String(A) + String(B) + String(C) + String(D)
//点击刷新验证码
i.onclick = function () {
    var A = parseInt(Math.random() * 10)
    var B = parseInt(Math.random() * 10)
    var C = parseInt(Math.random() * 10)
    var D = parseInt(Math.random() * 10)
    i.innerText = String(A) + String(B) + String(C) + String(D)
    console.log(i.innerText)
}
//给密码书写正则   必须包含大小写字母和数字的组合，可以使用特殊字符，长度在8-10之间
var reg = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$/
//获取注册按钮
var div = document.querySelector('form>div')
console.log(div)
//获取password的值
var pas = document.querySelector('form>input:nth-of-type(4)')
console.log(pas)
//密码不规范的提示信息
var tishi = $('form>h1')
//获取确认密码的值
var pas2 = document.querySelector('form>input:nth-of-type(5)')
console.log(pas2)
//密码不一致的提示信息
var tishi2 = $('form>h2')
//获取密码正确的提示信息
var tishi3 = $('form>h3')

pas.oninput = function () {
    h6.style.opacity=0
    // console.log(pas.value)
    //如果错了，需要显示提示框
    if (!reg.test(pas.value)) {
        tishi3.text('密码不正确')
        tishi3.css({ display: 'block' })
        if (pas.value === '') {
            tishi.css({ display: 'none' })
            tishi3.css({ display: 'none' })
            if (pas2.value === "") {
                tishi3.css({ display: 'none' })
                tishi2.css({ display: 'none' })
            }
        }
        else {
            if (pas.value != pas2.value) {
                tishi2.text('密码不一致')
                tishi2.css({ display: 'block' })
            }
            tishi.css({ display: 'block' })
        }


    }
    //若果正则正确
    if (reg.test(pas.value)) {
        tishi3.text('密码正确')
        tishi3.css({ display: 'block' })
        tishi.css({ display: 'none' })
        if (pas.value == pas2.value) {
            tishi2.text('密码一致')
            tishi2.css({ display: 'block' })
        }

    }
}
pas2.oninput = function () {
    h6.style.opacity=0
    if (pas.value == pas2.value) {
        if (pas2.value === '') {
            tishi2.css({ display: 'none' })
        } else {
            tishi2.text('密码一致')
            tishi2.css({ display: 'block' })
        }
    }
    if (pas.value != pas2.value) {
        tishi2.text('密码不一致')
        tishi2.css({ display: 'block' })

    }
}
//给密码注册查看事件

var mmlook = document.querySelector('.mmlook')
var x = 0

mmlook.onclick = function () {
    if (x % 2 === 0) {
        this.style.textDecoration = "line-through", pas.type = "text"
        return x++
    }
    if (x % 2 !== 0) {
        this.style.textDecoration = "none", pas.type = "password"
        return x++
    }
}
//给确认密码注册查看事件
var mm2look = document.querySelector('.mm2look')
var x2 = 0

mm2look.onclick = function () {
    if (x2 % 2 === 0) {
        this.style.textDecoration = "line-through", pas2.type = "text"
        return x2++
    }
    if (x2 % 2 !== 0) {
        this.style.textDecoration = "none", pas2.type = "password"
        return x2++
    }
}
//点击注册页面
var btn = document.querySelector('form>div')
var dv = document.querySelector('body>div')
var daojishi = document.querySelector('body>div>s')
var section = document.querySelector('section')
var input = $('input')
console.log(input)
var ipt=document.querySelectorAll('input')
ipt[1].oninput=function(){
    h6.style.opacity=0
}
ipt[2].oninput=function(){
    h6.style.opacity=0 
    console.log(ipt[2].value)
}
// console.log(btn,dv,daojishi)
//点击之前要判断上面所有的数据都填写完毕。
btn.onclick = function () {
  //判断不符合条件
        if (!regs.test(shouji.value)||!reg.test(pas.value)||pas.value!=pas2.value||$('input:eq(1)').value==''||ipt[2].value!=i.innerText||!ipt[5].checked){
            section.style.display = 'none'
            h6.style.opacity=1
        }
        else {
            //判断符合条件，定时器结束进入登录页面
            section.style.display = 'block'
            document.body.style.background = "rgba(0,0,0,.5)"
            dv.style.display = 'block'
            h6.style.opacity=0
        var shoujizhi=shouji.value
        console.log(shoujizhi)
        var mimazhi=pas.value
        console.log(mimazhi)
            setInterval(() => {
                console.log(daojishi.innerText)
                daojishi.innerText--
                if(daojishi.innerText==1){
                    location.href=`./登录.html?shoujizhi=${shoujizhi}&mimazhi=${mimazhi}`
                }
            }, 1000);

        }
    



}